package com.nianzhen.recruitment;


import android.util.Log;
import android.view.View;
import android.widget.Button;

public abstract class BaseNetFragmentActivity extends BaseFragmentActivity{

	private Button mRetryBtn;
	
	protected View mNoNetLayout;
	protected View mLoadingLayout;
	protected View mDataLayout;
	
	@Override
	public void setContentView(int layoutResID) {		
		super.setContentView(layoutResID);
		initNetLayout();
        Log.d("Base","getClass-->"+getLocalClassName());
	}

	protected void initNetLayout() {
		mNoNetLayout = findViewById(R.id.no_net_layout);
		mLoadingLayout = findViewById(R.id.loading_layout);
		mDataLayout = findViewById(R.id.content_layout);
		mRetryBtn = (Button)findViewById(R.id.net_retry_btn);
		if(mRetryBtn != null){
			mRetryBtn.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					loadData();
				}
			});
		}
	}

	protected abstract void loadData();
	
    protected void toLoadingLayout(){
    	if(mNoNetLayout != null){
    		mNoNetLayout.setVisibility(View.GONE);
    	}
    	if(mLoadingLayout != null){
    		mLoadingLayout.setVisibility(View.VISIBLE);
    	}
    	if(mDataLayout != null){
    		mDataLayout.setVisibility(View.GONE);
    	}
    }
    
    protected void toNoNetLayout(){
    	if(mNoNetLayout != null){
    		mNoNetLayout.setVisibility(View.VISIBLE);
    	}
    	if(mLoadingLayout != null){
    		mLoadingLayout.setVisibility(View.GONE);
    	}
    	if(mDataLayout != null){
    		mDataLayout.setVisibility(View.GONE);
    	}
    }
    
    protected void toDataLayout(){
    	if(mNoNetLayout != null){
    		mNoNetLayout.setVisibility(View.GONE);
    	}
    	if(mLoadingLayout != null){
    		mLoadingLayout.setVisibility(View.GONE);
    	}
    	if(mDataLayout != null){
    		mDataLayout.setVisibility(View.VISIBLE);
    	}
    }
}
